package cj.web.admin.controllers;

import java.util.List;
import net.paoding.rose.web.annotation.Path;
import net.paoding.rose.web.annotation.rest.Get;
import net.paoding.rose.web.annotation.rest.Post;
import net.paoding.rose.web.var.Model;
import net.sf.json.JSONObject;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import cj.web.admin.dao.AppTokenDAO;
import cj.web.admin.domain.AppToken;
import cj.web.constants.MemuEnum;

@Path("/appToken")
public class AppTokenController{

	private static Logger logger = Logger.getLogger(AppTokenController.class.getName());
	
	@Autowired
	private AppTokenDAO appTokenDao;
	
	@Get("show")
	public String show(Model model,AppToken appToken) {
		//MemuEnum
        model.add("MemuEnum",MemuEnum.dxgl);
		return "/views/game/tokenList.vm";
	}

	@Post("getList")
	public String queryList(AppToken appToken) {
	
		JSONObject jo = new JSONObject();
		
		List<AppToken> objs = appTokenDao.query(appToken);
		
		for(AppToken obj:objs){
			if(1==obj.getState()){
				obj.setStateName("有效");
			}else{
				obj.setStateName("无效");
			}
		}
		
		int size = appTokenDao.querysize(appToken);
		jo.put("data", objs);
		jo.put("draw", appToken.getDraw());
		jo.put("recordsTotal", size);
		jo.put("recordsFiltered", size);
		return "@"+jo.toString();
	}
}